
export class StringUtils {
    // 被混淆的字符串，每个字符都在35-125之间
    // 每个字符的ASCII码值加上2，并保证字符的ASCII码值在35-125之间
    public static confuseString(str: string): string {
        let result = "";
        for (let i = 0; i < str.length; i++) {
            let charCode = str.charCodeAt(i);
            charCode += 2;
            if (charCode > 125) {
                charCode = 35 + (charCode - 125);
            }
            result += String.fromCharCode(charCode);
        }
        return result;
    }

    // 解密混淆的字符串
    // 每个字符的ASCII码值减去2，并保证字符的ASCII码值在35-125之间
    public static deconfuseString(str: string): string {
        let result = "";
        for (let i = 0; i < str.length; i++) {
            let charCode = str.charCodeAt(i);
            charCode -= 2;
            if (charCode < 35) {
                charCode = 125 - (35 - charCode);
            }
            result += String.fromCharCode(charCode);
        }
        return result;
    }

}